//System includes
#include <iostream>
#include <Windows.h>
#include <assert.h>

// Engine includes
#include "Vector3.h"
#include "Camera.h"
#include "Window.h"
#include "Game.h"
#include "Renderer.h"
#include "pg2_directinput.h"
#include "Engine.h"

#include "CamMover.h"

#define MINPOS -0.5f
#define MAXPOS 0.5f

class TestyGame : public MegaEngine::Game
{
	MegaEngine::ColorVertex * vertexs;
	
	CamMover* camMover;

	float a;
	bool cosa, tUp;
public:
	TestyGame(HINSTANCE hInstance) : Game(hInstance) {}
	virtual bool End(bool correctTermination)
	{
		
		//assert(correctTermination);
		
		if(vertexs)
			delete[] vertexs;
		return true;
	}
	virtual bool Init()
	{
		camMover = new CamMover(engine->GetMainCamera(), engine->GetInput());
		
		a = 0;
		cosa = true;
		tUp = true;

		vertexs = new MegaEngine::ColorVertex[4];
		vertexs[0].x = MINPOS;
		vertexs[0].y = MINPOS;
		vertexs[0].z = 0;
		vertexs[0].color = 0xff0000;

		vertexs[1].x = MINPOS;
		vertexs[1].y = MAXPOS;
		vertexs[1].z = 0;
		vertexs[1].color = 0xff0000;
		
		vertexs[2].x = MAXPOS;
		vertexs[2].y = MINPOS;
		vertexs[2].z = 0;
		vertexs[2].color = 0x00ff00;
		
		vertexs[3].x = MAXPOS;
		vertexs[3].y = MAXPOS;
		vertexs[3].z = 0;
		vertexs[3].color = 0x00ff00;
		
		return vertexs != NULL;
	}
	
	virtual bool Loop()
	{
		camMover->OnLoop();

		//a += 0.1;
		engine->GetRenderer()->setMatrixMode(MegaEngine::World);
		engine->GetRenderer()->loadIdentity();
		//engine->GetRenderer()->RotateX(20);
		//engine->GetRenderer()->RotateY(20);
		engine->GetRenderer()->RotateY(DEG_TO_RAD(a));
		//engine->GetRenderer()->Translate(0,0,-5);
		engine->GetRenderer()->Scale(6,3,1);

		exit = !engine->GetRenderer()->Draw(MegaEngine::TriangleStrip, 4, vertexs);

		// camera update
		
		/*
		engine->GetRenderer()->setMatrixMode(MegaEngine::View);
		engine->GetRenderer()->loadIdentity();
		engine->GetRenderer()->Translate(camX, camY, camZ);
		/**/
		return true;
	}
};

int WINAPI WinMain( HINSTANCE hInstance,    // HANDLE TO AN INSTANCE.  This is the "handle" to YOUR PROGRAM ITSELF.  More in the GLOSSARY at the bottom.
                    HINSTANCE hPrevInstance,// USELESS on modern windows (totally ignore hPrevInstance)
                    LPSTR szCmdLine,        // Command line arguments.  Explained near BOTTOM of this file.
                    int iCmdShow )
{
	TestyGame* test = new TestyGame(hInstance);
	test->Start();

	delete test;
	return 0;
}